//
//  AppendSettingShowView.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/9/10.
//

#import "AppendSettingShowView.h"
@interface AppendSettingShowView ()


@property (nonatomic ,strong) UIView * makeView;
@property (nonatomic ,assign) CGFloat viewH;

@property (nonatomic ,strong) UIView * topview;
@property (nonatomic ,strong) UIImageView * topseledImg;
@property (nonatomic ,strong) UIImageView * buttomseledImg;
@property (nonatomic ,strong) UIView * buttomview;
@property (nonatomic ,strong) GYWclickBlock oneblock;
@property (nonatomic ,strong) GYWclickBlock allblock;

@end
@implementation AppendSettingShowView
+ (void)showViewWithType:(int)type oneBlock:(GYWclickBlock)oneblock andallBlock:(GYWclickBlock)allblock{
    AppendSettingShowView * view = [AppendSettingShowView new];
    [[DTKTool getCurrentVC].view addSubview:view];
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    view.viewH = kwt(370) + KSafeAreaBottomHeight;
    view.oneblock = oneblock;
    view.allblock = allblock;
    UIView * makeView = [UIView new];
    view.makeView = makeView;
    makeView.backgroundColor = KcolorHex(@"#F1F4FB");
    makeView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, view.viewH);
    [view addSubview:makeView];
    [DTKTool BFYJ:kwt(15) andView:makeView andCorner:UIRectCornerTopLeft|UIRectCornerTopRight andSize: CGRectMake(0, 0 ,SCREEN_WIDTH, view.viewH)];
    
    //    view.userInteractionEnabled = YES;
    //    [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(dismiss)]];
    makeView.userInteractionEnabled = YES;
    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(noclick)]];
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(dismiss)]];
    makeView.userInteractionEnabled = YES;
    [makeView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:view action:@selector(noclick)]];
    
    UILabel * titlab = [DTKTool labelWithText:@"请选择设置方式" andFont:kCFont(18) andTextColor:KcolorHex(@"#242729")];
    [makeView addSubview:titlab];
    [titlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(20));
    }];
    
    
    UIButton * btn = [UIButton buttonWithType:0];
    [btn setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
    btn.addTarget(view,@selector(dismiss));
    [makeView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-15));
        make.width.height.offset(kwt(20));
        make.centerY.equalTo(titlab);
    }];
    __weak typeof(view) weakView = view;

    UIView * topview = [UIView new];
    view.topview = topview;
    topview.backgroundColor = KcolorHex(@"#EEF4FF");
    if(type == 1){
        [DTKTool YJBK:kwt(5) andView:topview andWidth:1 andColor:KcolorHex(@"#0967FF")];
    } else {
        [DTKTool YJBK:kwt(5) andView:topview andWidth:1 andColor:KcolorHex(@"#CEDBEA")];
    }
    [makeView addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(64));
        make.width.offset(kwt(330));
        make.height.offset(kwt(115));
    }];
    
    topview.addClickBlock(^{
        [weakView leftBtnclick];
    });
    UIImageView * topimg = kimageView(@"single");
    [topview addSubview:topimg];
  
    [topimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(15));
        make.top.offset(kwt(16));
        make.width.height.offset(kwt(52));
    }];
    
    UILabel * topbtlab = [DTKTool labelWithText:@"设置当前池塘" andFont:kCFont(18) andTextColor:KcolorHex(@"#383F47")];
    [topview addSubview:topbtlab];
    [topbtlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(78));
        make.top.offset(kwt(21));
    }];
    
    UILabel * topnrlab = [DTKTool labelWithText:@"重新设置当前池塘的信息和工作" andFont:kFont(14) andTextColor:KcolorHex(@"#7B7F84")];
    [topview addSubview:topnrlab];
    [topnrlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(78));
        make.top.offset(kwt(48));
    }];
    
    UIImageView * topseledImg = kimageView(@"");
    if(type == 1){
        topseledImg.image = [UIImage imageNamed:@"complete"];
    }
    [DTKTool YJBK:kwt(10) andView:topseledImg andWidth:1 andColor:KcolorHex(@"#B3C5D8")];
    view.topseledImg = topseledImg;
    [topview addSubview:topseledImg];
    [topseledImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topimg);
        make.right.offset(kwt(-15));
        make.width.height.offset(kwt(20));
    }];
    UIView * topdbview = [UIView new];
    topdbview.backgroundColor = KcolorHex(@"#F7F2F2");
    [topview addSubview:topdbview];
    [topdbview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(kwt(37));
    }];
    UILabel * toptslab = [DTKTool labelWithText:@"*操作成功后，将不再与其他池塘批量下发任务" andFont:kFont(14) andTextColor:KcolorHex(@"#EF571A")];
    [topdbview addSubview:toptslab];
    [toptslab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.centerY.offset(0);
    }];
    
    UIView * buttomview = [UIView new];
    view.buttomview = buttomview;
    buttomview.backgroundColor = KcolorHex(@"#EEF4FF");
    if(type == 2){
        [DTKTool YJBK:kwt(5) andView:buttomview andWidth:1 andColor:KcolorHex(@"#0967FF")];
    } else {
        [DTKTool YJBK:kwt(5) andView:buttomview andWidth:1 andColor:KcolorHex(@"#CEDBEA")];
    }
    [makeView addSubview:buttomview];
    [buttomview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(195));
        make.width.offset(kwt(330));
        make.height.offset(kwt(152));
    }];
    buttomview.addClickBlock(^{
        [weakView rightbtnclick];
    });
    UIImageView * buttomimg = kimageView(@"single");
    [buttomview addSubview:buttomimg];
    [buttomimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(15));
        make.top.offset(kwt(16));
        make.width.height.offset(kwt(52));
    }];
    
    UILabel * buttombtlab = [DTKTool labelWithText:@"同步设置" andFont:kCFont(18) andTextColor:KcolorHex(@"#383F47")];
    [buttomview addSubview:buttombtlab];
    [buttombtlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(78));
        make.top.offset(kwt(21));
    }];
    
    UILabel * buttomnrlab = [DTKTool labelWithText:@"同步修改当前池塘与同时创建的\n其他池塘的信息和工作" andFont:kFont(14) andTextColor:KcolorHex(@"#7B7F84")];
    [buttomview addSubview:buttomnrlab];
    buttomnrlab.numberOfLines = 2;
    [buttomnrlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(78));
        make.top.offset(kwt(48));
    }];
    UIImageView * buttomseledImg = kimageView(@"");
    if(type == 2){
        buttomseledImg.image = [UIImage imageNamed:@"complete"];
    }
    [DTKTool YJBK:kwt(10) andView:buttomseledImg andWidth:1 andColor:KcolorHex(@"#B3C5D8")];
    view.buttomseledImg = buttomseledImg;
    [buttomview addSubview:buttomseledImg];
    [buttomseledImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(buttomimg);
        make.right.offset(kwt(-15));
        make.width.height.offset(kwt(20));
    }];
    UIView * buttomdbview = [UIView new];
    buttomdbview.backgroundColor = KcolorHex(@"#F7F2F2");
    [buttomview addSubview:buttomdbview];
    [buttomdbview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(kwt(54));
    }];
    UILabel * buttomtslab = [DTKTool labelWithText:@"*操作成功后，批量创建所有池塘的工作内容也将\n同步变更" andFont:kFont(14) andTextColor:KcolorHex(@"#EF571A")];
    [buttomdbview addSubview:buttomtslab];
    buttomtslab.numberOfLines = 2;
    [buttomtslab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.centerY.offset(0);
    }];
    
 
  

    [view show];
    
    
}
- (void)leftBtnclick{
    if(self.oneblock){
        self.oneblock();
    }
    [self dismiss];
}

- (void)rightbtnclick{
    if(self.allblock){
        self.allblock();
    }
    [self dismiss];
}

- (void)show{
    [[DTKTool getCurrentVC].view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(0, SCREEN_HEIGHT - self.viewH , SCREEN_WIDTH, self.viewH);
    } completion:^(BOOL finished) {
    }];
}
- (void)noclick{}
- (void)dismiss{
    [UIView animateWithDuration:0.25 animations:^{
        self.makeView.frame = CGRectMake(0, SCREEN_HEIGHT , SCREEN_WIDTH, self.viewH);
    } completion:^(BOOL finished) {
        [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        [self removeFromSuperview];
    }];
}


@end
